﻿using AutoMapper;
using ITTestingSystem.BusinessLogic.Enums;
using ITTestingSystem.Domain.Entities;
using ITTestingSystem.Models.Account;
using ITTestingSystem.Models.Tests;

namespace ITTestingSystem.Extentions.Modules.AutoMapper
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    public class ConfigureProfile : Profile
    {
        /// <summary>
        /// 
        /// </summary>
        /// 
        protected override void Configure()
        {
            CreateMap<Test, TestViewModel>()
                .ForMember
                (
                    testView => testView.Title,
                    option => option.MapFrom(test => test.Title)
                )
                .ForMember
                (
                    testView => testView.Description,
                    option => option.MapFrom(test => test.TestsDescription.Description)
                )
                .ForMember
                (
                    testView => testView.TimeLimit,
                    option => option.MapFrom(test => test.TestsDescription.TimeLimit)
                )
                .ForMember
                (
                    testView => testView.QuestionNumber,
                    option => option.MapFrom(test => test.Questions.Count)
                )
                .ForMember
                (
                    testView => testView.Topics,
                    option => option.MapFrom(test => test.TestsDescription.TopicsInTest)
                );

            CreateMap<RegisterViewModel, User>()
                .ForMember
                (
                    user => user.FirstName,
                    option => option.MapFrom(register => register.FirstName)
                )
                .ForMember
                (
                    user => user.LastName,
                    option => option.MapFrom(register => register.LastName)
                )
                .ForMember
                (
                    user => user.Email,
                    option => option.MapFrom(register => register.Email)
                )
                .ForMember
                (
                    user => user.AuthenticationsDetail,
                    option => option.MapFrom(register => new AuthenticationsDetail
                              {
                                  PasswordHash = register.Password,
                                  Login = register.Login
                              })
                )
                .ForMember
                (
                    user => user.Role,
                    option => option.Ignore()
                )
                .ForMember
                (
                    user => user.Id,
                    option => option.Ignore()
                )
                .ForMember
                (
                    user => user.CompletedTestsDetails,
                    option => option.Ignore()
                )
                .ForMember
                (
                    user => user.RoleId,
                    option => option.UseValue(UserRole.User)
                );
        }
    }
}